Add built-in unit aliases for currency and generic units#396
Merged
Conversation
Add dollar ($, Dollar, Dollars, $s) and generic unit (Unit, Units) equivalence classes to the built-in unit aliases. These match the default unit equivalences that Vensim ships with, improving compatibility when importing Vensim models that use these units without explicit equivalence declarations. https://claude.ai/code/session_01SFHWDB5sKsuobFpi8wQhLP
Code ReviewReviewed the changes in No bugs found. The implementation correctly follows the established pattern for builtin unit aliases (matching
Verdict: Correct. The patch introduces no bugs and existing code/tests will not break. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #396 +/- ##
==========================================
+ Coverage 76.57% 76.60% +0.02%
==========================================
Files 143 143
Lines 37026 37026
==========================================
+ Hits 28353 28363 +10
+ Misses 8673 8663 -10 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This change adds two new built-in unit definitions to the Simlin engine to improve unit handling for common use cases: currency (dollar) and generic units.
Key Changes
"$"as a built-in unit with aliases"dollar","dollars", and"$s"to standardize currency unit handling"unit"as a built-in unit with alias"units"for generic dimensionless unit referencestest_builtin_dollar_equivalences(): Verifies that$,Dollar,Dollars, and$sall resolve to the same unit and that they properly cancel out in ratiostest_builtin_unit_equivalences(): Verifies thatUnitandUnitsboth resolve to theunitunitImplementation Details
The built-in units follow the same pattern as existing aliases like
"person"/"people". They are registered in thebuiltin_unitsarray in theContext::new_with_builtins()method, ensuring they are only added if the model doesn't already define units with those names. The tests confirm that case-insensitive matching works correctly and that unit cancellation operates as expected.https://claude.ai/code/session_01SFHWDB5sKsuobFpi8wQhLP